package cn.tedu.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class SysTimeAspect {
    //定义切入点
    @Pointcut("bean(productController)")
    public void doTime(){}

    @Before("doTime()")
    public void doBefore(JoinPoint jp) {
        System.out.println("doBefore()");
    }

    @After("doTime()")
    public void doAfter() {
        System.out.println("doAfter()");
    }

    //核心业务代码正常结束时执行
    @AfterReturning("doTime()")
    public void doAfterReturing() {
        System.out.println("doAfterReturing()");
    }

    //核心业务代码出现异常时执行
    @AfterThrowing("doTime()")
    public void doAfterThrowing() {
        System.out.println("doAfterThrowing()");
    }

    @Around("doTime()")
    public Object doAround(ProceedingJoinPoint jp) throws Throwable {
        System.out.println("doAround.before");
        Object obj = jp.proceed();
        System.out.println("doAround.after");
        return obj;
    }
}
